<?php

namespace App\Http\Controllers\Home;

use App\Model\Cate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CommonController extends Controller
{
    //获取所有的分类
    public function __construct()
    {
        $cate = Cate::get();
        $cateone = [];
        $catetwo = [];

        foreach ($cate as $k => $v)
        {
            if ($v->cate_pid == 0)
            {
                $cateone[$k] = $v;
                //获取二级类
                foreach ($cate as $m => $n)
                {
                    if ($v->cate_id == $n->cate_pid)
                    {
                        $catetwo[$k][$m] = $n;
                    }
                }
            }
        }
//        dd($cateone);
        view()->share('cateone', $cateone);
        view()->share('catetwo', $catetwo);

    }
}
